#![feature(entry_insert)]
#![feature(result_option_inspect)]
// #![allow(unused)]

pub mod data;
pub mod util;

mod cluster;
mod db_manager;
mod invoker;
mod script_engine;
mod service_engine;
mod support;

pub use cluster::EaiServer;
pub use db_manager::{DbConnManager, DbConnection};
pub use invoker::{InvokerManager, InvokerServer};
pub use service_engine::{
    ServiceComponent, ServiceComponentBase, ServiceContext, ServiceContextBase,
    ServiceContextBuilder, ServicePlugin, ServicePluginBase,
};

pub use support::Config as CoreConfig;

/// initialize core moudles
pub fn initialize(core_config: &CoreConfig) -> common_base::prelude::Result<()> {
    DbConnManager::initialize(core_config.db_config_file.as_str())?;

    InvokerManager::initialize(
        core_config.service_container_dir.as_str(),
        core_config.service_dylib_dir.as_str(),
    );

    let local_eai_server = EaiServer::initialize(
        core_config.eai_server_file.as_str(),
        core_config.local_eai_server_id.as_str(),
    )?;

    InvokerServer::initialize(local_eai_server)?;

    Ok(())
}
